package com.dys.controller;

import com.dys.pojo.User;
import com.dys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @className: com.dys.controller.UserController
 * @description: com.dys.controller
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/31 22:56
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("login.action")
    public ModelAndView getUserInfo(String username, String password) {
        ModelAndView mv = new ModelAndView();
        Map<String, Object> model = mv.getModel();
        model.put("msg", "脏话,你好");
        User user = userService.getUserInfoByUsernameAndPassword(username, password);
        if (user != null) {
            System.out.println("登录成功!");
            mv.setViewName("forward:/success.jsp");
        } else {
            mv.setViewName("forward:/error.jsp");
        }
        return mv;
    }

    @RequestMapping("login2.action")
    public String getUserInfo2(String username, String password) {
        User user = userService.getUserInfoByUsernameAndPassword(username, password);
        if (user != null) {
            System.out.println("登录成功!");
            return "forward:/success.jsp";
        }
        return "forward:/error.jsp";
    }
}
